package com.fzkj.bio.part4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * 任务对象
 */
public class ServerRunnbleTarget implements Runnable{

    private Socket socket;

    public ServerRunnbleTarget(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            // 创建输入流
            InputStream is = socket.getInputStream();
            // 包装为字符输入流
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String msg;
            while((msg = reader.readLine()) != null) {
                System.out.println("接收到客户端消息：" + msg);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
